package io.gitee.zhangbinhub.acp.cloud.hello.controller

import io.gitee.zhangbinhub.acp.boot.log.LogAdapter
import io.gitee.zhangbinhub.acp.cloud.annotation.AcpCloudDuplicateSubmission
import io.gitee.zhangbinhub.acp.cloud.tools.CloudTools
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.noear.solon.annotation.*
import org.noear.solon.core.util.MimeType
import org.noear.solon.cloud.annotation.CloudBreaker
import org.noear.solon.core.handle.Context
import org.noear.solon.validation.annotation.Valid

@Api("控制器")
@Valid
@Controller
open class TestController(
    private val logAdapter: LogAdapter,
    private val cloudTools: CloudTools
) {
    @ApiOperation("test-hello")
    @Get
    @Produces(MimeType.TEXT_PLAIN_VALUE)
    @Mapping("/hello")
    @CloudBreaker("hello")
    @AcpCloudDuplicateSubmission
    fun hello(context: Context, name: String): String {
        logAdapter.info("request headers: ${context.headerMap()}")
        logAdapter.info("request name: $name")
        val respon = "hello[${cloudTools.getServerIp()}] response: name=$name"
        logAdapter.info(respon)
        return respon
    }
}